package com.edu.data;

import java.io.Serializable;

public class Page implements Serializable {
    int start;     //当前页开始索引
    int pageSize;  //每页的记录条数
    int total;     //总共记录条数

    int totalPage;  //总页数
    boolean hasPre;  //是否有上一页
    boolean hasNext; //是否有下一页
    int last;	//最后一页开始索引

    public Page(int total, int start, int pageSize){
        this.total=total;
        this.start=start;
        this.pageSize=pageSize;
    }

    public int getStart() {
        return start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    /**
     * 计算总共分成多少页
     * @return 总页数
     */
    public int getTotalPage() {
        if (total%pageSize==0){
            totalPage=total/pageSize;
        }else {
            totalPage=total/pageSize+1;
        }
        if (totalPage==0){
            totalPage=1;
        }
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    /**
     * 判断有没有上一页
     * @return
     */
    public boolean isHasPre() {
        if (start==0)
            return false;
        else
            return true;

    }

    public void setHasPre(boolean hasPre) {
        this.hasPre = hasPre;
    }

    /**
     * 判断有没有下一页
     * @return
     */
    public boolean isHasNext() {
        if (start==getLast())
            return false;
        else
            return true;
    }

    public void setHasNext(boolean hasNext) {
        this.hasNext = hasNext;
    }

    /**
     * 计算尾页（最后一页）开始索引
     * @return
     */
    public int getLast() {
        int last;
        if (total%pageSize==0){
            last=total-pageSize;
        }else {
            last=total-total%pageSize;
        }
        last = last < 0 ? 0 : last;
        return last;
    }

    public void setLast(int last) {
        this.last = last;
    }
}
